	function UI_EvintaIbe() { };
	
	UI_EvintaIbe.intMaxInf = 3;
	
	var intMaxPax = 6;
	arrErr = arrErr;
	var strDefDateFormat = "DD/MM/YYYY";
	var intMaxSearchDays= 331;
	var strDDMMMMYYY="DD MMMM YYYY";
	var notAllowedDays = -1;
	var notAllowedHours = 0;
	
	/* Flight Tab Validations */
    UI_EvintaIbe.validateFlightSearch = function () {
        
		if(!UI_EvintaIbe.bkgValidate()){
			return false;
		}
        return true;
    }
	
	 /* Build Flight Search Data */
    UI_EvintaIbe.buildFlightSearchData = function () {
        var strHdnData = "";
		strHdnData += ($("input[name='radBTrip']:checked").val()) + " ^";
		strHdnData += ($('#chkFlexibleDate').attr('checked') ? "FLEX" : "LF_NEW") + " ^";
        strHdnData += objSelFrom.value + " ^";
        strHdnData += objSelFrom.text + " ^";
        strHdnData += objSelTo.value + " ^";
        strHdnData += objSelTo.text + " ^";
		strHdnData += ($("#txtDDay").val()).substr(0,2) + " ^";
        strHdnData += ($("#txtDDay").val()).substr(3,($("#txtDDay").val()).length) + " ^";
		if($("input[name='radBTrip']:checked").val()=="R"){
			strHdnData += ($("#txtRDay").val()).substr(0,2) + " ^";
			strHdnData += ($("#txtRDay").val()).substr(3,($("#txtRDay").val()).length) + " ^";
		}else{
			strHdnData += " ^";
			strHdnData += " ^";
		}
        strHdnData += $("#selBAdt").val() + " ^";
        strHdnData += $("#selBChld").val() + " ^";
        strHdnData += $("#selBInf").val() + " ^";
        strHdnData += $("#selBCos").val() + " ^";       
		strHdnData += $("#selBFType").val() + " ^";
		strHdnData += " ^";
		strHdnData += " ^";
		strHdnData += getText("selBCos")+ " ^";
		strHdnData += getText("selBFType")+ " ^";
		strHdnData += "BKG" + " ^"
		strHdnData += UI_EvintaIbe.getSelectedCountryCode(objSelFrom.value) + " ^";
		strHdnData += " ^";
        $("#hdnData").val(strHdnData);
        $("#hdnMode").val("BKG");

    }
	
	/* Flights */
    UI_EvintaIbe.ratBTripOnClick = function () {
        $("#divRT").hide();
        $("#divRTC").hide();
        $("#spnRDay").hide();
        
        switch ($("input[name='radBTrip']:checked").val()) {
            case "O":
                $("#chkFlexibleDate").attr("checked", false);
                $("#chkFlexibleDate").attr("disabled", true);
                break;

            case "R":
                $("#chkFlexibleDate").attr("disabled", false);
                $("#divRT").show();
                $("#divRTC").show();
                $("#spnRDay").show();
                break;
        }
    }
	
	UI_EvintaIbe.selBAdtOnChange = function () {
        var intAdults = $("#selBAdt").val();
        var intInf = $("#selBInf").val();
        intAdults = Number(intAdults)
        if (intAdults > UI_EvintaIbe.intMaxInf) {
            intAdults = UI_EvintaIbe.intMaxInf;
        }
        intAdults = intAdults + 1;
 
        var objC = document.getElementById("selBInf");
        objC.length = 0;
 
        var intLen = objC.length;
        for (var i = 0; i < intAdults; i++) {
            intLen = objC.length;
            objC.length = objC.length + 1
            objC.options[intLen].value = i;
            objC.options[intLen].text = i;
        }
 
        $("#selBInf").val(intInf);
    }
	
	/* Manage Booking Validations */
    UI_EvintaIbe.validateManageBooking = function () {
        if ($("#txtMBPNR").val() == "") {
            alert("PNR cannot be blank");
            $("#txtMBPNR").focus();
            return false;
        }

        if ($("#txtMBLN").val() == "") {
            alert("Last Name cannot be blank");
            $("#txtMBLN").focus();
            return false;
        }

        return true;
    }
	
	/* Manage Booking Build Data  */
    UI_EvintaIbe.buildManageBookingData = function () {
        var strHdnData = "";
        strHdnData += $("#txtMBPNR").val() + " ^";
        strHdnData += $("#txtMBLN").val() + " ^";

        $("#hdnData").val(strHdnData);
        $("#hdnMode").val("MB");
    }
	
	
	/*Initialize error message */
	UI_EvintaIbe.pgInitializeErrMsg = function (){
		strErrMsg = "";
	} 
	
	/*Show error messages */
	UI_EvintaIbe.pgShowErrMsg = function(strMsg){
		alert(strMsg);
	} 
	
	/*Set return enable disable*/
	UI_EvintaIbe.dateChangeFlt1 = function(strID){
		try{
			var strControl = "";
			var strDivCntrl = "";
			switch (strID){
				case 0 :
					strControl = "txtDDay";
					strDivCntrl = "spnDDay";
					break;
				case 1 :
					strControl = "txtRDay";
					strDivCntrl = "spnRDay";
					break;
			}
			if (!dateChk(strControl, strDefDateFormat)){
				setField(strControl, strDefDateFormat);
			}
			
			if ((trim(getValue(strControl)) == strDefDateFormat) || (trim(getValue(strControl)) == "")){
				setField(strControl, strDefDateFormat);
				DivWrite(strDivCntrl, "");
			}else{
				DivWrite(strDivCntrl, getWDay(getValue(strControl)).toUpperCase());
			}
		}catch(ex){

		}
		
	}
	
	/* IBE flight validations */
	UI_EvintaIbe.bkgValidate = function () {
		UI_EvintaIbe.pgInitializeErrMsg();
		if (objSelFrom.value == "") {
            alert("Please Select the Origin");
            return false;
        }

        if (objSelTo.value == "") {
            alert("Please Select the Destination");
            return false;
        }
		
		if (strErrMsg == "") {
			var intTotPax = Number(getValue("selBAdt"));
			intTotPax += Number(getValue("selBChld"));
			intTotPax += Number(getValue("selBInf"));
			if (intMaxPax < intTotPax) {
				var tmpString = "While booking a ticket on our website, please keep in mind the following rules regarding number of guests in a traveling:\n\n1.A maximum of 6 guests per traveling party.\n\n2.A Child booking has to have an accompanying Adult booking in order to be valid.\n\n3. Each Infant ticket booked will have to have a corresponding Adult Ticket booked.\n    Eg:- For 2 infant tickets, 2 adult tickets are mandatory.";
				strErrMsg = buildError(tmpString);
				setFocus("selBAdt")
			}
		}
		if (strErrMsg == "") {
			if (objSelFrom.value == objSelTo.value) {
				strErrMsg = buildError(arrErr['003']);
				objSelTo.focus()
			}
		}
		
		// Validating the route check
		/*if (strErrMsg == "") {
			if (objSelFrom.value != "CMB" && objSelFrom.value != "HRI"){
				if (objSelTo.value != "CMB" && objSelTo.value != "HRI"){
					strErrMsg = buildError("From " + objSelFrom.text + " available route is " + objSelFrom.text + " - Colombo/Mattala.");
					objSelTo.focus()
				}
			}
		}*/
		
		var strDeptDt = trim(getValue("txtDDay"));
		var strRetuDt = trim(getValue("txtRDay"));
		
		if ((strDeptDt == strDefDateFormat) || (strDeptDt == "")){
			strErrMsg = buildError(arrErr["001"], "Date");
			setFocus("txtDDay");
		}
		
		if ($("input[name='radBTrip']:checked").val() == "R") {
			if ((strRetuDt == strDefDateFormat) || (strRetuDt == "")){
				strErrMsg = buildError(arrErr["001"], "Date");
				setFocus("txtRDay");
			}
		}
		
		if (strErrMsg == "") {
			if (!CheckDates(UI_Widget.strPrmSysDate, strDeptDt)) {
				strErrMsg = buildError(arrErr['011'], "Departure Date");
				setFocus("txtDDay");
			}
			var tmpDate = DateToString(addDays(StringToDate(UI_Widget.strPrmSysDate),
					intMaxSearchDays));
			if (strErrMsg == "" && !CheckDates(strDeptDt, tmpDate)) {
				strErrMsg = buildError(arrErr['021'], "Departure Date", tmpDate);
				setFocus("txtDDay");
			}
			if (strErrMsg == "" && $("input[name='radBTrip']:checked").val() == "R") {
				if (!CheckDates(strRetuDt, tmpDate)) {
					strErrMsg = buildError(arrErr['021'], "Return Date", tmpDate);
					setFocus("txtRDay");
				}
			}
			
			var tmpMinDate = DateToString(addDays(StringToDate(UI_Widget.strPrmSysDate),	notAllowedDays -1));
		    if (strErrMsg == "" && CheckDates(strDeptDt, tmpMinDate)) {
					strErrMsg = buildError(arrErr['023'], notAllowedHours);
					setFocus("txtDDay");
		    }
			
			if (strErrMsg) {
				alert(strErrMsg);
				return false
			}

		    tmpMinDate = DateToString(addDays(StringToDate(UI_Widget.strPrmSysDate),	notAllowedDays));
		    if (strErrMsg == "" && CheckDates(strDeptDt, tmpMinDate)) {
		        strErrMsg = buildError(arrErr['023'], notAllowedHours);
		        alert(strErrMsg);
				strErrMsg ="";
		    }
			
		}
		if ($("input[name='radBTrip']:checked").val() == "R") {
			if (strErrMsg == "") {
				if (!CheckDates(UI_Widget.strPrmSysDate, strRetuDt)) {
					strErrMsg = buildError(arrErr['011'], "Return Date");
					setFocus("txtRDay");
				}
			}
			if (strErrMsg == "") {
				if (!CheckDates(strDeptDt, strRetuDt)) {
					strErrMsg = buildError(arrErr['006'], "Return Date", "Departure Date");
					setFocus("txtRDay");
				}
			}
		}
		
		if (strErrMsg) {
			UI_EvintaIbe.pgShowErrMsg(strErrMsg);
			return false
		}

		return true
	}
	
	/*Get selected Country code.*/
	UI_EvintaIbe.getSelectedCountryCode = function (stationCode) {
		for ( var i = 0; i < arrFrmCityOptTags.length; i++) {
			if (arrFrmCityOptTags[i][0] == stationCode) {
				return arrFrmCityOptTags[i][2]
      }
		}
		return ""
	}
	
	/*Set Progress custom messages.*/
	UI_EvintaIbe.setProgressCusMessages = function () {
		try {
			strHeader1 = objSelFrom.text + "(" + objSelFrom.value + ") - ";
			strHeader1 += objSelTo.text + "(" + objSelTo.value + ")";
			strHeader2 = "Departing - ";
			strHeader2 += dateChk(getValue("txtDDay"), strDDMMMMYYY);
			strHeader2 += " ("+ getWDayText(getValue("txtDDay")) + ")";
			if ($("input[name='radBTrip']:checked").val()  == "R") {
				strHeader2 += " Returning  - ";
				strHeader2 += dateChk(getValue("txtRDay"), strDDMMMMYYY);
				strHeader2 += " (" + getWDayText(getValue("txtRDay")) + ")"
			}
		} catch (e) {
		}
		$('<input>').attr({type: 'hidden',id: 'hdnHeader1',name: 'hdnHeader1'}).appendTo('#frmPost');
		$('<input>').attr({type: 'hidden',id: 'hdnHeader2',name: 'hdnHeader2'}).appendTo('#frmPost');
		$("#hdnHeader1").val(strHeader1);
        $("#hdnHeader2").val(strHeader2);
		$("#hdnSourceURL").val(UI_Widget.strPrmHomeURL);
		
	}